package com.wicket.okrbff.biz.service.impl;

import cn.hutool.core.bean.BeanUtil;
import com.wicket.okrbff.biz.service.SystemDockingService;
import com.wicket.okrbff.biz.service.dto.req.*;
import com.wicket.okrbff.biz.service.dto.res.*;
import com.wicket.okrbff.common.ro.OkrResult;
import com.wicket.okrbff.common.ro.OkrResult;
import com.wicket.okrbff.common.util.CommonFunctionHelper;
import com.wicket.okrbff.common.util.RedisUtil;
import javax.annotation.Resource;
import org.apache.skywalking.apm.toolkit.trace.Tag;
import org.apache.skywalking.apm.toolkit.trace.Tags;
import org.apache.skywalking.apm.toolkit.trace.Trace;
import org.springframework.stereotype.Service;
import com.wicket.okrcomponent.integration.FwCompSystemDockingClient;
import com.wicket.okrcomponent.integration.dto.QueryDatabaseConfAnswerDetailComRespDto;
import com.wicket.okrcomponent.integration.dto.QueryDatabaseConfAnswerDetailComReqDto;
import com.wicket.okrframework.integration.FwBaseBusinessObjectClient;
import com.wicket.okrframework.integration.dto.QueryObjAttributeListComRespDto;
import com.wicket.okrframework.integration.dto.QueryObjAttributeListComReqDto;
import com.wicket.okrcomponent.integration.dto.ImplementImportExcelFileDataComRespDto;
import com.wicket.okrcomponent.integration.dto.ImplementImportExcelFileDataComReqDto;
import com.wicket.okrcomponent.integration.dto.BaseMetadataObjectPropertyDto;
import java.util.stream.Collectors;
import cn.hutool.core.collection.CollectionUtil;
import com.wicket.okrbff.common.exception.Assert;

/**
 * @author ：
 * @date ：
 *
 *
 * @version 1.0
 */
@Service
public class SystemDockingServiceImpl implements SystemDockingService {

  @Resource
  private RedisUtil redisUtil;
@Resource
  FwCompSystemDockingClient fwCompSystemDockingClient;

@Resource
  FwBaseBusinessObjectClient fwBaseBusinessObjectClient;
/**
   * B2执行导入excel文件数据(管理)[8751]
   * gen by moon at 3/23/2024, 8:22:22 PM
   */
    @Trace(operationName = "B2执行导入excel文件数据(管理)")
    @Tags({@Tag(key = "参数",value = "arg[0]"),
            @Tag(key = "返回值",value = "returnedObj")})
  @Override
  public BffImplementImportExcelFileDataRespDto implementImportExcelFileData(BffImplementImportExcelFileDataReqDto reqDto){
      
       
       //步骤0: D2查询数据库配置答案(公共) - queryDatabaseConfAnswerDetailCom
     QueryDatabaseConfAnswerDetailComRespDto queryDatabaseConfAnswerDetailComRespDto = null;
    QueryDatabaseConfAnswerDetailComReqDto queryDatabaseConfAnswerDetailComReqDto=new QueryDatabaseConfAnswerDetailComReqDto();
  if(reqDto!=null){
      queryDatabaseConfAnswerDetailComReqDto.setBusinessObjectCode(reqDto.getBusinessObjectCode());//SimpleFieldAssign//sourceId:1639375_1
    }
  
    /*D2查询数据库配置答案(公共)[8753]   */
    Assert.isNull(queryDatabaseConfAnswerDetailComReqDto.getBusinessObjectCode(),"B2执行导入excel文件数据(管理)-D2查询数据库配置答案(公共)-业务对象编码不能为空",false);
      queryDatabaseConfAnswerDetailComRespDto = fwCompSystemDockingClient.queryDatabaseConfAnswerDetailCom(queryDatabaseConfAnswerDetailComReqDto).getData()/*vcase invoke 跨dubbo调用;*/;
      
      
      
    
//步骤1: D1查询对象属性列表(公共) - queryObjAttributeListCom
     QueryObjAttributeListComRespDto queryObjAttributeListComRespDto = null;
    QueryObjAttributeListComReqDto queryObjAttributeListComReqDto=new QueryObjAttributeListComReqDto();
  queryObjAttributeListComReqDto.setSubjectLifeCycle("CURRENTLY_VALID");//sourceId:1637865_1
queryObjAttributeListComReqDto.setSpaceId(CommonFunctionHelper.getBaseInfoFromLocal().getSpecSpaceId());//CURRENT_SPACEID//sourceId:1637867_1
if(reqDto!=null){
      queryObjAttributeListComReqDto.setBusinessObjectCode(reqDto.getBusinessObjectCode());//SimpleFieldAssign//sourceId:1637864_1
    }
  
    /*D1查询对象属性列表(公共)[8748]   */
    Assert.isNull(queryObjAttributeListComReqDto.getBusinessObjectCode(),"B2执行导入excel文件数据(管理)-D1查询对象属性列表(公共)-业务对象编码不能为空",false);
Assert.isNull(queryObjAttributeListComReqDto.getSubjectLifeCycle(),"B2执行导入excel文件数据(管理)-D1查询对象属性列表(公共)-主体生命周期不能为空",false);
Assert.isNull(queryObjAttributeListComReqDto.getSpaceId(),"B2执行导入excel文件数据(管理)-D1查询对象属性列表(公共)-创建于空间ID不能为空",false);
      queryObjAttributeListComRespDto = fwBaseBusinessObjectClient.queryObjAttributeListCom(queryObjAttributeListComReqDto).getData()/*vcase invoke 跨dubbo调用;*/;
      
      
      
    
//步骤2: D2执行导入excel文件数据(公共) - implementImportExcelFileDataCom
     ImplementImportExcelFileDataComRespDto implementImportExcelFileDataComRespDto = null;
    if(queryDatabaseConfAnswerDetailComRespDto !=null){
          ImplementImportExcelFileDataComReqDto implementImportExcelFileDataComReqDto=new ImplementImportExcelFileDataComReqDto();
  if(queryDatabaseConfAnswerDetailComRespDto!=null){
      implementImportExcelFileDataComReqDto.setDatabaseName(queryDatabaseConfAnswerDetailComRespDto.getDatabaseName());//SimpleFieldAssign//sourceId:1637854_1
implementImportExcelFileDataComReqDto.setDatabaseAddress(queryDatabaseConfAnswerDetailComRespDto.getDatabaseAddress());//SimpleFieldAssign//sourceId:1637855_1
implementImportExcelFileDataComReqDto.setDatabasePort(queryDatabaseConfAnswerDetailComRespDto.getDatabasePort());//SimpleFieldAssign//sourceId:1637856_1
implementImportExcelFileDataComReqDto.setDatabaseUserId(queryDatabaseConfAnswerDetailComRespDto.getDatabaseUserId());//SimpleFieldAssign//sourceId:1637857_1
implementImportExcelFileDataComReqDto.setDatabasePassWord(queryDatabaseConfAnswerDetailComRespDto.getDatabasePassWord());//SimpleFieldAssign//sourceId:1637858_1
    }
if(reqDto!=null){
      implementImportExcelFileDataComReqDto.setFileContent(reqDto.getFileContent());//SimpleFieldAssign//sourceId:1637860_1
implementImportExcelFileDataComReqDto.setBusinessObjectCode(reqDto.getBusinessObjectCode());//SimpleFieldAssign//sourceId:1637859_1
    }
if(queryObjAttributeListComRespDto!= null&&  queryObjAttributeListComRespDto.getBaseMetadataObjectPropertyList() !=null&& !CollectionUtil.isEmpty(queryObjAttributeListComRespDto.getBaseMetadataObjectPropertyList())){
      implementImportExcelFileDataComReqDto.setBaseMetadataObjectPropertyList(queryObjAttributeListComRespDto.getBaseMetadataObjectPropertyList().stream().map(item -> BeanUtil.toBean(item, BaseMetadataObjectPropertyDto.class)).collect(Collectors.toList()));//objList-to-objLists//sourceId:1637861_1
    }
  
    /*D2执行导入excel文件数据(公共)[8746]   */
    Assert.isNull(implementImportExcelFileDataComReqDto.getDatabaseName(),"B2执行导入excel文件数据(管理)-D2执行导入excel文件数据(公共)-数据库名称不能为空",false);
Assert.isNull(implementImportExcelFileDataComReqDto.getDatabaseAddress(),"B2执行导入excel文件数据(管理)-D2执行导入excel文件数据(公共)-数据库地址不能为空",false);
Assert.isNull(implementImportExcelFileDataComReqDto.getDatabasePort(),"B2执行导入excel文件数据(管理)-D2执行导入excel文件数据(公共)-数据库端口不能为空",false);
Assert.isNull(implementImportExcelFileDataComReqDto.getDatabaseUserId(),"B2执行导入excel文件数据(管理)-D2执行导入excel文件数据(公共)-数据库用户名不能为空",false);
Assert.isNull(implementImportExcelFileDataComReqDto.getDatabasePassWord(),"B2执行导入excel文件数据(管理)-D2执行导入excel文件数据(公共)-数据库密码不能为空",false);
Assert.isNull(implementImportExcelFileDataComReqDto.getFileContent(),"B2执行导入excel文件数据(管理)-D2执行导入excel文件数据(公共)-文件内容不能为空",false);
Assert.isNull(implementImportExcelFileDataComReqDto.getBusinessObjectCode(),"B2执行导入excel文件数据(管理)-D2执行导入excel文件数据(公共)-业务对象编码不能为空",false);
      implementImportExcelFileDataComRespDto = fwCompSystemDockingClient.implementImportExcelFileDataCom(implementImportExcelFileDataComReqDto).getData()/*vcase invoke 跨dubbo调用;*/;
      
      
      
           }
    
BffImplementImportExcelFileDataRespDto retData = new BffImplementImportExcelFileDataRespDto();
  
  

  
  
return retData;
  }
  //
}
